const mongoose = require('mongoose');

//链接数据库，test集合
mongoose.connect('mongodb://localhost:27017/test', {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useFindAndModify: false,
});

// mongoose.set('useFindAndModify', false)
const Schema = mongoose.Schema;


//创建一个Schema的实例,设计表结构
const goodsinfoSchema = new Schema(
  {
    status: Number,
    message: [
      {
        id: {
          type: String,
          required: true,
        },
        title: {
          type: String,
          required: true,
        },
        add_time: {
          type: Date,
          required: true,
          default: Date.now(),
        },
        goods_no: {
          type: String,
          required: true,
        },
        stock_quantity: {
          type: Number,
          required: true,
        },
        market_price: {
          type: Number,
          required: true,
        },
        sell_price: {
          type: Number,
          required: true,
        },
        img_url: {
          type: String,
          required: true,
        }
      },
    ],
  },
  // 关联lunbotu集合
  { collection: 'goodsinfo' }
);

//创建并导出模型构造函数
const Goodsinfo = mongoose.model('Goodsinfo', goodsinfoSchema);
module.exports = Goodsinfo;
